﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kaiser.Modules.Core.Aggregates;
using Kaiser.Modules.Core.Aggregates.Enum;
using Kaiser.Modules.Core.Aggregates.Product;

namespace Kaiser.Modules.Core.Services
{
    public class Machines
    {
        private Aggregates.Account 操作员;

        public Machines(Aggregates.Account 操作员)
        {
          
            this.操作员 = 操作员;
        }

        /// <summary>
        ///处理销售订单
        /// </summary>
        /// <param name="company"></param>
        public void OrderSaleBill(Aggregates.Company company)
        {
            #region 添加销售订单

            var order = SaleOrderBills.Create();
            order.CreateDateTime = DateTime.Now;
            order.LastUpdateDateTime = DateTime.Now;
            order.GetAmount = 300;//收了定金300元
            order.Company = company;
            order.User = 操作员;

            //order.SaleOrderBillItems.Add(new SaleOrderBillItems(Product.Get(0))
            //{
            //    ItemCount = 1,
            //    ShowItemCount = 1,
            //    ShowPrice = 540,
            //    Price = 520,
            //    Amount = 520
            //});

            //order.SaleOrderBillItems.Add(new SaleOrderBillItems(Product.Get(1))
            //{
            //    ItemCount = 1,
            //    ShowItemCount = 1,
            //    ShowPrice = 700,
            //    Price = 650,
            //    Amount = 520
            //});

            order.BillCode = CoreServiceFactory.CreateBillCodeService().GenerationBillCode(BillCodeService.BillCodeType.销售订单);
            order.Remark = "DH:0000021";
            order.BillState = BillStateEnum.执行中;
            order.SettleAcct = SettleAcct.GetSettleAcctByName("现金");
            order.BillAmount = order.SaleOrderBillItems.Sum(x => x.Amount);
            CoreServiceFactory.CreateSaleOrderService().Add(order);



            #endregion
        }

      
    }
}
